﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FCNS.KeepMoney.Util
{
    /// <summary>
    /// 升级组件状态
    /// </summary>
    public enum UpdateComponentStatus
    {
        /// <summary>
        /// 未知
        /// </summary>
        Unknown = 0,
        /// <summary>
        /// 已是最新版本
        /// </summary>
        UpToDate,
        /// <summary>
        /// 新版本可用
        /// </summary>
        NewVerAvailable,
        /// <summary>
        /// 旧的发行版本
        /// </summary>
        PreRelease,
        /// <summary>
        /// 下载失败
        /// </summary>
        DownloadFailed
    }
    /// <summary>
    /// 组件升级信息
    /// </summary>
    public sealed class UpdateComponentInfo
    {
        private readonly string m_strName; // Never null
        /// <summary>
        /// 获取组件名称
        /// </summary>
        public string Name
        {
            get { return m_strName; }
        }

        private readonly ulong m_uVerInstalled;
        /// <summary>
        /// 获取已安装版本号
        /// </summary>
        public ulong VerInstalled
        {
            get { return m_uVerInstalled; }
        }

        private ulong m_uVerAvailable = 0;
        /// <summary>
        /// 获取或设置可更新的版本号
        /// </summary>
        public ulong VerAvailable
        {
            get { return m_uVerAvailable; }
            set { m_uVerAvailable = value; }
        }

        private UpdateComponentStatus m_status = UpdateComponentStatus.Unknown;
        /// <summary>
        /// 获取或设置升级组件状态 <see cref="UpdateComponentStatus"/>
        /// </summary>
        public UpdateComponentStatus Status
        {
            get { return m_status; }
            set { m_status = value; }
        }

        private readonly string m_strUpdateUrl; // Never null
        /// <summary>
        /// 获取升级地址
        /// </summary>
        public string UpdateUrl
        {
            get { return m_strUpdateUrl; }
        }

        private readonly string m_strCat; // Never null
        /// <summary>
        /// 获取所属分类
        /// </summary>
        public string Category
        {
            get { return m_strCat; }
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="strName">名称</param>
        /// <param name="uVerInstalled">已安装版本</param>
        /// <param name="strUpdateUrl">升级地址</param>
        /// <param name="strCategory">所属分类</param>
        public UpdateComponentInfo(string strName, ulong uVerInstalled,
            string strUpdateUrl, string strCategory)
        {
            if (strName == null) throw new ArgumentNullException("strName");
            if (strUpdateUrl == null) throw new ArgumentNullException("strUpdateUrl");
            if (strCategory == null) throw new ArgumentNullException("strCategory");

            m_strName = strName;
            m_uVerInstalled = uVerInstalled;
            m_strUpdateUrl = strUpdateUrl;
            m_strCat = strCategory;
        }
    }
}
